package com.reef.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.reef.dto.ReaderDto;
import com.reef.entity.Reader;
import com.reef.entity.Result;
import com.reef.service.TeacherService;
	
@RestController
public class TeacherController {
	@Autowired
	private TeacherService tsService;
	
	/**
	 * 多条件动态查询
	 */
	@RequestMapping("/selTeacherAll")
	public Object selTeacherAll(ReaderDto tDto,int page,int limit) {
		Pageable pageable = PageRequest.of(page-1, limit);
		Page<Reader> list  = tsService.selTeacherAll(tDto, pageable);
		Map<String,Object > map=new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", list.getTotalElements());
		map.put("data", list.getContent());
		return map;
	}
	/**
	 * 查询科室
	 */
	@RequestMapping("selSection")
	public Object selSection() {
		return tsService.selSection();
	}
	/**
	 * 添加教师信息
	 */
	
	@RequestMapping("/insertTea")
	public Object insertTea(Reader reader) {
		Reader i=tsService.insertTea(reader);
		if(i==null) {
			return new Result("添加失败","",false);
		}else {
			return new Result("添加成功","",true);
		}
	}
	/**
	 * 修改教师信息
	 */
	@RequestMapping("/updateTea")
	public Object updateTea(Reader reader) {
		Reader i=tsService.updateTea(reader);
		if(i==null) {
			return new Result("修改失败","",false);
		}else {
			return new Result("修改成功","",true);
		}
	}
}
